#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/3/27 10:16
# @Author  : Rem~
# @File    : 000CreateSineSignal.py
# @function: matplotlib与numpy的联合使用

import numpy as np
import matplotlib.pyplot as plt
# sample frequency
fs = 100
# signal frequency
f = 1
# sample point
N = 1000
# x axis
x = np.linspace(0, N, N)
# x = range(1, N)
# amplitude
amp = 2**12
sig = amp*np.cos(2*np.pi*f*(x/fs))

plt.subplot(2, 1, 1)
plt.plot(x, sig, "-b")
plt.xlabel("sample point")
plt.ylabel("signal amplitude(LSB)")
plt.grid(True)

sig_fft = np.fft.fft(sig)
sig_fft_abs = np.abs(sig_fft)/N*2
plt.subplot(2, 1, 2)
# plt.plot(x[0:int(N/2)-1]/N*fs, sig_fft_abs[0:int(N/2)-1])
plt.stem(x[0:int(N/2)-1]/N*fs, sig_fft_abs[0:int(N/2)-1])
plt.xlabel("frequency axis(MHz)")
plt.ylabel("signal amplitude(LSB)")
plt.grid(True)

plt.show()
